package com.dhu.cst.ningtianzhe181310419.test.ui.notifications;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.dhu.cst.ningtianzhe181310419.test.Info;
import com.dhu.cst.ningtianzhe181310419.test.R;
import com.dhu.cst.ningtianzhe181310419.test.RegisterActivity;
import com.dhu.cst.ningtianzhe181310419.test.RegisterPasswordActivity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class NotificationsFragment extends Fragment {
    String dongtaiJson;
    ListView listView;
    SimpleAdapter simpleAdapter;
    List<HashMap<String, Object>> list;
    HashMap<String,Object>map;
    private NotificationsViewModel notificationsViewModel;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        notificationsViewModel =
                ViewModelProviders.of(this).get(NotificationsViewModel.class);
        View root = inflater.inflate(R.layout.fragment_notifications, container, false);

        listView = root.findViewById(R.id.dongtaiListView);
        initMessageList();
        simpleAdapter = new SimpleAdapter(root.getContext(),list,R.layout.dongtaiview,new String[]{"name","message"},new int[]{R.id.name,R.id.message});
        listView.setAdapter(simpleAdapter);
        return root;
    }

    public List<HashMap<String,Object>> initMessageList(){
        list = new ArrayList<HashMap<String, Object>>();
        map = new HashMap<String, Object>();
        map.put("name", "10086");
        map.put("message", Info.dongtaiString);
        list.add(map);
        map = new HashMap<String, Object>();
        map.put("name", "同学A");
        map.put("message", Info.dongtaiString);
        list.add(map);
        map = new HashMap<String, Object>();
        map.put("name", "同学B");
        map.put("message", Info.dongtaiString);
        list.add(map);
        map = new HashMap<String, Object>();
        map.put("name", "同学C");
        map.put("message", Info.dongtaiString);
        list.add(map);
        return list;
    }

}